<template>
	<view class="medical">

		<!-- <view class="erduan " style=";width: 100%;background-color: white;top:0;z-index: 999;
		height: 140rpx;">
			<view class="w100" v-for="(i,index) in top_list" :key="index">
				<view class="cflex" @click="topId=index">
					<image :src="i.img" mode="widthFix" class="wid38"></image>
					<text class="f14 c35 mt5" :class="{'top_sele':index == topId}">{{i.title}}</text>
				</view>
			</view>
		</view> -->
		<!-- <view class="" style="height: 140rpx;"></view> -->

		<!-- 按XX查找列表 -->
		<view class="chazhao">
			<view class="chazhao-yi">
				<view class="chazhao-yi-left">
					<view class="chazhao-yi-left-nr">
						按品类查找
					</view>

				</view>
				<!-- 标签 -->
				<scroll-view class="scroll-view_H" scroll-x="true">
					<view class="scroll-view_H-vs">
						<view v-for="(i,index) in tag_list" :key="index" class="tag"
							:class="{'tag_sele':condex == index}" @click="getCategory(i,index)"
							@longtap="onLongPres(i)">
							{{i.uname}}
						</view>
						<view class="tag" @click="listAdd()">
							<uni-icons type="plusempty" size="18" color="#08B69F"></uni-icons>
						</view>
					</view>
				</scroll-view>
				<!-- </view> -->

			</view>
			<view class="chazhao-er">
				<view class="chazhao-er-left">
					<view class="chazhao-er-left-nr">
						按种类查找
					</view>
				</view>
				<view class="chazhao-er-right">
					<view class="chazhao-er-right-sou">
						<image src="/static/img/index/search.png" mode="widthFix" class=" search-icons"></image>
						<input type="text" v-model="input" placeholder="输入症状,药品,品牌" class="search" placeholder-style="
						font-size:26rpx;color:ccc;" @click="">
					</view>
					<view class="" @click="getSoa">
						<image src="/static/img/index/ma.png" mode="widthFix" class="wid20"></image>
					</view>

				</view>
			</view>
		</view>
		<view class="" style="display: flex;">
			<view class="left">
				<scroll-view class="wid87 scroll-view_HH" scroll-y="true" style="padding-top: 10rpx;">
					<view style="line-height: 50rpx; border-bottom: 1rpx solid #ccc;" :class="{'nav_bg':index == navId}"
						v-for="(i,index) in nav_list" :key="index" @click="getUcategoryName(i,index)" @longtap="onLongPress(i
						)">
						<text :class="{'nav_sele':index == navId}" class="f14 c6 pl18">{{i.uproducttypename}}</text>
					</view>
					<view style="line-height: 50rpx; text-align: center;" @click="listAdds()">

						<uni-icons type="plusempty" size="18" color="#08B69F"></uni-icons>
					</view>
				</scroll-view>
			</view>
			<view class="right">
				<view class="right-banner">
					<image src="/static/img/index/banner.png" mode="widthFix" style="height: 200rpx; width: 100%;">
					</image>
				</view>
				<view class=" flex">

					<view :class="['conter',act== index?'red':'']" v-for="(i,index) in list" :key="index"
						@click="$pub.go(good_url+'?id='+i.uproductid,act=index)" @longtap="getLongpress(i.uproductid)">
						<view class="conter-hd">
							<image :src="$url + i.uproductPic" mode=""></image>
						</view>
						<view class="conter-db">
							{{i.utradeName}}
						</view>
					</view>
					<view class="cflex" style="width: 33%;" @click="$pub.go(good_url)">
						<view class="flex-cen" style="height: 140rpx; border: 2rpx solid #08B69F;width: 80%;
						border-radius: 10rpx;background: #FFFFFF;">
							<view class="" style="color: #08B69F;font-size: 60rpx;">
								+
							</view>
						</view>
						<text class="f14 c35">添加新品</text>
					</view>
				</view>
			</view>
		</view>
		<uni-popup ref="popup" type="dialog">
			<view class="listpopup">
				<view class="listpopup-hd">
					添加
				</view>
				<view class="listpopup-center">
					<view class="">
						<input type="text" placeholder="品类名称" v-model="category">
					</view>
					<view class="">
						<input type="text" placeholder="品类位置" v-model="location">
					</view>
				</view>
				<view class="listpopup-db">
					<view class="" @click="close">
						取消
					</view>
					<view class="" @click="confirm">
						确认
					</view>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="popup2" type="dialog">
			<view class="listpopup">
				<view class="listpopup-hd">
					添加
				</view>
				<view class="listpopup-center">
					<view class="">
						<input type="text" placeholder="类型名称" v-model="uproducttypename">
					</view>
					<!-- <view class="" v-else>
						<input type="text" placeholder="类型名称" v-model="uproducttypename2">
					</view> -->
					<view class="">
						<input type="text" placeholder="类型位置" v-model="uproductTypeSpace">
					</view>
					<!-- 	<view class="">
						<input type="text" placeholder="类型" v-model="uform">
					</view> -->
				</view>
				<view class="listpopup-db">
					<view class="" @click="closes">
						取消
					</view>
					<view class="" @click="kindAdd">
						确认
					</view>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="popup3" type="dialog">
			<view class="listpopup">
				<view class="listpopup-hd">
					添加/删除
				</view>
				<view class="listpopup-center">
					<view class="">
						<input type="text" placeholder="类型名称" v-model="uproducttypename2">
					</view>
					<!-- <view class="" v-else>
						<input type="text" placeholder="类型名称" v-model="uproducttypename2">
					</view> -->
					<view class="">
						<input type="text" placeholder="类型位置" v-model="uproductTypeSpace2">
					</view>
					<!-- 	<view class="">
						<input type="text" placeholder="类型" v-model="uform">
					</view> -->
				</view>
				<view class="listpopup-db">
					<view class="" @click="getQu()">
						删除
					</view>
					<view class="" @click="kindXiu()">
						修改
					</view>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="popup4" type="dialog">
			<view class="listpopup">
				<view class="listpopup-hd">
					添加/删除
				</view>
				<view class="listpopup-center">
					<view class="">
						<input type="text" placeholder="品类名称" v-model="uname2">
					</view>
					<!-- <view class="" v-else>
						<input type="text" placeholder="类型名称" v-model="uproducttypename2">
					</view> -->
					<view class="">
						<input type="text" placeholder="品类位置" v-model="uplace2">
					</view>
					<!-- 	<view class="">
						<input type="text" placeholder="类型" v-model="uform">
					</view> -->
				</view>
				<view class="listpopup-db">
					<view class="" @click="getSha()">
						删除
					</view>
					<view class="" @click="getXiu()">
						修改
					</view>
				</view>
			</view>
		</uni-popup>
		<!-- 提示窗示例 -->
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog cancelText="关闭" confirmText="同意" title="通知" content="确认删除吗？" @confirm="dialogConfirm"
				@close="dialogClose"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				act: 0,
				uproductid: null,
				usortName: '',
				topId: 0,
				findId: 0,
				navId: 0,
				input: '',
				ucategoryId: '',
				usortId: '',
				img: '/static/img/medical/yao.png',
				good_url: '/pages/medical/good/good',

				top_list: [{
						img: '/static/img/medical/up.png',
						title: '上架管理'
					},
					{
						img: '/static/img/medical/hui.png',
						title: '惠城管理'
					},
					{
						img: '/static/img/medical/pi.png',
						title: '批发管理'
					},
					{
						img: '/static/img/medical/bu.png',
						title: '补货通知'
					},
					{
						img: '/static/img/medical/up.png',
						title: '库房管理'
					},
				],
				nav_list: [],
				tag_list: [],
				good_list: [{
						img: '/static/img/medical/yao.png',
						title: '感冒发烧'
					},
					{
						img: '/static/img/medical/yao.png',
						title: '感冒发烧'
					},
					{
						img: '/static/img/medical/yao.png',
						title: '感冒发烧'
					},
					{
						img: '/static/img/medical/yao.png',
						title: '感冒发烧'
					},
					{
						img: '/static/img/medical/yao.png',
						title: '感冒发烧'
					},
					{
						img: '/static/img/medical/yao.png',
						title: '感冒发烧'
					},
					{
						img: '/static/img/medical/yao.png',
						title: '感冒发烧'
					},

					{
						img: '/static/img/medical/yao.png',
						title: '感冒发烧'
					},
					{
						img: '/static/img/medical/yao.png',
						title: '感冒发烧'
					},
					{
						img: '/static/img/medical/yao.png',
						title: '感冒发烧'
					},
					{
						img: '/static/img/medical/yao.png',
						title: '感冒发烧'
					},
					{
						img: '/static/img/medical/yao.png',
						title: '感冒发烧'
					},
					{
						img: '/static/img/medical/yao.png',
						title: '感冒发烧'
					},

					{
						img: '/static/img/medical/yao.png',
						title: '感冒发烧'
					},

				],
				list: [],
				category: '',
				location: '',
				createBy: '',
				createTime: '',
				params: '',
				uform: '',
				remark: '',
				ulevel: '', //1
				updateBy: '',
				updateTime: '',
				uproductTypePic: '', //1
				uproductTypeSpace: '', //1
				uproducttypeid: '',
				uproducttypename: '',
				uparentid: '',
				searchValue: '',
				condex: null,
				uproducttypename2: '',
				uproductTypeSpace2: '',
				uproducttypeid2: '',
				uplace2: '',
				uname2: '',
				id2: '',
			}

		},
		onLoad() {


		},
		onShow() {
			this.getList()
			// this.getLists()
			this.getTab()
			this.getKind()
		},
		watch: {
			input(e) {
				console.log(e);
				if (e == '') {
					this.getList()
				} else {
					this.getInput()
				}
			}
		},
		computed: {
			...mapState({
				deviceInfo: state => state.deviceInfo,
			})
		},
		methods: {
			// changeAct(index){ 
			// 	console.log(index,8888);
			// },
			getInput() {
				this.request({
					url: '/web/mall/product/like?compName=' + this.input + '&pinleiid=' + this.usortId +
						'&leixingid=' + this.ucategoryId,
				}).then(res => {
					this.list = res.data
					console.log(res, 20);
				})
			},
			getUcategoryName(i, index) {
				console.log(i, index);
				this.navId = index
				this.ucategoryName = i.uproducttypename
				this.ucategoryId = i.uproducttypeid
				this.getLists()
			},
			getCategory(i, index) {
				console.log(111);
				console.log(i, index);
				this.condex = index
				this.usortName = i.uname
				this.usortId = i.id
				this.getLists()
			},
			getVariety(i, index) {

			},
			getLongpress(id) {
				this.$refs.alertDialog.open()
				console.log(id);
				this.uproductid = id
			},
			dialogClose() {
				this.$refs.alertDialog.close()
			},
			dialogConfirm() {
				this.request({
					url: '/web/mall/product/deleteXtProductByUproductid?uproductid=' + this.uproductid + '',
					method: 'DELETE',
				}).then(res => {
					if (res.code == 200) {
						this.$refs.alertDialog.close()
						this.getList()
					}
				})
			},
			onLongPres(i) {
				console.log(i);
				this.id2 = i.id
				this.uplace2 = i.uplace
				this.uname2 = i.uname
				this.$refs.popup4.open()
			},
			getSha() {
				this.request({
					url: '/category/dels/' + this.id2 + '',
					method: 'DELETE',
				}).then(res => {
					if (res.code == 200) {
						this.$refs.popup4.close()
						this.getTab()
					}
				})
			},
			getXiu() {
				this.request({
					url: '/category/edit',
					method: 'PUT',
					data: {
						delFle: '',
						id: this.id2,
						uname: this.uname2,
						uplace2: this.uplace2
					}
				}).then(res => {
					if (res.code == 200) {
						this.$refs.popup4.close()
						this.getTab()
					}
				})
			},
			onLongPress(i) {
				console.log(i.uproductTypeSpace, );
				this.uproducttypename2 = i.uproducttypename
				this.uproductTypeSpace2 = i.uproductTypeSpace
				this.uproducttypeid2 = i.uproducttypeid
				this.$refs.popup3.open()
			},
			getQu() {
				this.request({
					url: '/mall/product/type/del/' + this.uproducttypeid2 + '',
					method: 'DELETE'
				}).then(res => {
					if (res.code == 200) {
						this.$refs.popup3.close()
						this.getKind()
						// this.category = null
						// this.location = null
					}
				})
			},
			kindXiu() {
				this.request({
					url: '/mall/product/type/xg?name=' + this.uproducttypename2 + '&space=' + this
						.uproductTypeSpace2 + '&id=' + this.uproducttypeid2 + '',
					method: 'PUT',
					// data:{ 
					// 	space:this.uproductTypeSpace2,
					// 	id:this.uproducttypeid2,
					// 	name:this.uproducttypename2,
					// }
				}).then(res => {
					console.log(res, 666);
					if (res.code == 200) {
						this.$refs.popup3.close()
						this.getKind()
						// this.category = null
						// this.location = null
					}
				})
			},
			findChange(id) {
				this.findId = id
			},
			getLists() {
				console.log(this.usortName, '品');
				console.log(this.ucategoryName);
				this.request({
					url: '/web/mall/product/selectProductByPlAndZl',
					method: 'POST',
					data: {
						usortName: this.ucategoryName,
						ucategoryName: this.usortName
					}
				}).then(res => {
					this.list = res.data
				})
			},
			getList() {
				this.request({
					url: '/web/mall/product/selectAllProduct',
				}).then(res => {
					this.list = res.data
				})
			},
			listAdd() {
				this.$refs.popup.open()
			},
			listAdds() {
				this.$refs.popup2.open()
			},
			close() {
				this.$refs.popup.close()
			},
			closes() {
				this.$refs.popup2.close()
			},
			confirm() {
				this.request({
					url: '/category/add',
					method: 'POST',
					data: {
						uname: this.category,
						uplace: this.location
					}

				}).then(res => {
					if (res.code == 200) {
						this.$refs.popup.close()
						this.getTab()
						this.category = null
						this.location = null
					}
					// console.log(res);
				})
			},
			getTab() {
				this.request({
					url: '/category/list',

				}).then(res => {
					console.log(res);
					this.tag_list = res.data
				})
			},

			getSoa() {
				// 只允许通过相机扫码
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
					}
				});
			},
			getKind() {
				this.request({
					url: '/mall/product/type/selectAllXtproductType',
					data: {
						pageNum: 1,
						pageSize: 999
					}
				}).then(res => {
					console.log(res);
					this.nav_list = res.data

				})
			},
			kindAdd() {
				this.request({
					url: '/mall/product/type/add',
					method: 'POST',
					data: {
						uform: this.uform,
						createBy: '',
						createTime: '',
						params: {},
						remark: '',
						searchValue: '',
						ulevel: '', //1
						uparentid: '',
						updateBy: '',
						updateTime: '',
						uproductTypePic: '', //1
						uproductTypeSpace: this.uproductTypeSpace, //1
						uproducttypeid: '',
						uproducttypename: this.uproducttypename,
					}
				}).then(res => {
					console.log(res);
					if (res.code == 200) {
						this.$refs.popup2.close()
						this.getKind()
						this.uproducttypename = null
						this.uproductTypeSpace = null
					}
					// this.nav_list = res.rows

				})
			}
			// getTab() {
			// 	this.request({
			// 		url: '/web​/mall​/product​/list',

			// 	}).then(res => {
			// 		console.log(res);
			// 		this.nav_list = res.rows
			// 	})
			// }
		}
	}
</script>

<style lang="less">
	.red {
		background-color: #F8662D;

		.conter-db {
			color: #fff;
			font-weight: 600;
		}

	}

	.right {
		flex: 1;
	}

	.right-banner {
		// width: 80%;
		padding: 20rpx;
	}

	.scroll-view_HH {
		white-space: nowrap;
		display: flex;
		flex-direction: column;
		// position: fixed;
		background-color: #F5F5F5;
		z-index: 99;
		// min-height: 90vh;
		// height: 500px;
	}

	.listpopup {
		// width: 100px;
		// height: 100px;
		// padding: 50rpx 100rpx;
		background-color: #fff;
		border-radius: 10rpx;

		.listpopup-hd {
			text-align: center;
			font-size: 30rpx;
			font-weight: 700;
			// margin-bottom: 20rpx;
			padding-top: 10rpx;
		}

		.listpopup-center {
			padding: 15rpx 40rpx;

			view {
				border: 1rpx solid #ccc;
				padding: 20rpx;
				border-radius: 10rpx;
				margin-top: 10rpx;
				color: #000;
				font-size: 30rpx;
			}
		}

		.listpopup-db {
			display: flex;
			border-top: 1rpx solid #ccc;

			view {
				width: 50%;
				padding: 20rpx 0;
				box-sizing: border-box;
				// border: 1rpx solid #ccc;
				text-align: center;
				font-size: 30rpx;

				&:nth-child(1) {
					border-right: 1rpx solid #ccc;
				}
			}
		}
	}

	.top_sele {
		background-color: #08B69F;
		border-radius: 22rpx;
		color: white;
		font-size: 28rpx;
		padding: 3rpx 15rpx;
		margin-top: 6rpx;
	}

	.find_sele {
		background-color: #08B69F;
		height: 4rpx;
		width: 52rpx;
		margin-top: 8rpx;
		border-radius: 4rpx;
	}

	.nav_sele {
		border-left: 6rpx solid #08B69F;
		color: #08B69F;
		padding-left: 29rpx;
	}

	.nav_bg {
		background-color: white;
	}

	.tag {
		border: 1rpx solid #DDDDDD;
		width: 152rpx;
		height: 46rpx;
		line-height: 46rpx;
		border-radius: 24rpx;
		font-size: 26rpx;
		color: #666666;
	}

	.tag_sele {
		background-color: #E7F7EC;
		color: #08B69F;
		border: 1rpx solid #E7F7EC;
	}

	.medical {
		overflow: hidden;
	}

	.erduan {
		overflow: hidden;
	}

	.flex {
		align-items: center;
	}

	.conter {
		// display: flex;
		padding: 14rpx 20rpx;

		.conter-hd {
			width: 130rpx;
			height: 130rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.conter-db {
			text-align: center;
			font-size: 30rpx;
			margin-top: 10rpx;
		}
	}

	.chazhao {
		.chazhao-yi {
			display: flex;
			align-items: center;

			.chazhao-yi-left {
				width: 28%;
				color: #fff;
				// padding: 20rpx;
				// height: 100rpx;
				// border-radius: 0 10rpx 10rpx 0;
				// border: 5rpx solid #08B69F;
				//  border-color:transparent #000 #000 transparent ;

				.chazhao-yi-left-nr {
					width: 188rpx;
					// height: 50rpx;
					// padding: 20rpx 0;
					line-height: 55rpx;
					text-align: center;
					position: relative;
					background-color: #08B69F;
					font-size: 28rpx;

					&:before {
						position: absolute;
						content: "";
						width: 0;
						height: 0;
						top: 0px;
						left: 186rpx;
						border-top: solid 26rpx transparent;
						border-left: solid 20rpx #08B69F;
						border-bottom: solid 30rpx transparent;
					}
				}

			}

			.scroll-view_H {
				width: 70%;
				white-space: nowrap;

				.scroll-view_H-vs {
					text-align: center;

					.tag {
						display: inline-block;
					}
				}
			}
		}

		.chazhao-er {
			display: flex;
			// align-items: center;
			margin-top: 20rpx;

			// background-color: #08B69F;
			.chazhao-er-left {
				width: 28%;
				color: #fff;
				// width: 22%;

				// padding: 20rpx;
				// color: #fff;
				.chazhao-er-left-nr {
					width: 193rpx;
					// padding: 20rpx 0;
					line-height: 50rpx;
					text-align: center;
					position: relative;
					background-color: brown;
					font-size: 28rpx;

					&:before {
						position: absolute;
						content: "";
						width: 0;
						height: 0;
						// z-index: 1000;
						top: 46rpx;
						left: 0rpx;
						border-top: solid 24rpx brown;
						border-right: solid 110rpx transparent;
						border-bottom: solid 25px transparent;
						border-left: solid 82rpx transparent;
					}
				}
			}

			.chazhao-er-right {
				width: 70%;
				// margin-left: 36rpx;
				box-sizing: border-box;
				position: relative;
				display: flex;
				align-items: center;

				// justify-content: space-between;
				.chazhao-er-right-sou {
					display: flex;
					align-items: center;
					margin-right: 10rpx;

					.search {
						padding: 0 12rpx 0 86rpx;
						letter-spacing: 5rpx;
						box-sizing: border-box;

					}

					.search-icons {
						// margin-top: 24rpx;
						margin-left: -20rpx
					}
				}

			}
		}
	}
</style>